﻿
crucible.NodeHelper = {

    bodyConverter: function () {
        var self = this,
            converter = Markdown.getSanitizingConverter(),
            convert = function (node) {
                self.node = node;
                return converter.makeHtml(node.Body() || "*Loading...*");
            };


        converter.hooks.chain("postConversion", function (text) {
            var node = self.node;
            if (node && node.Type() && node.Type() !== crucible.NodeType.assertion) {
                return text;
            }
            var finder = /\{\{\[([0-9]+)\]([^}]+)\}\}/g;
            var fixed = text.replace(finder, '<a href="#" class="assertionLink" data-id="$1">$2</a>');
            return fixed;
        });

        return {
            convert: convert
        };
    }()

};
